<?php include $this->admin_tpl('meta');?>
<title>添加内容 - YzmCMS内容管理系统</title>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/laydate/1.1/laydate.js"></script>
<script type="text/javascript" charset="utf-8" src="<?php echo STATIC_URL;?>plugin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="<?php echo STATIC_URL;?>plugin/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="<?php echo STATIC_URL;?>plugin/ueditor/lang/zh-cn/zh-cn.js"></script>
<style>
	.date{height:30px;padding:4px;width:265px;font-size:13px}.Hui-tags-token{color:#353535;}
	#colors{position:absolute;top:9px;right:23px;cursor:pointer;}
</style>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal mb-50" onsubmit="return checkall()" method="post">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value=""  name="title" onblur="check_title()">
				<input type="hidden" name="color" id="color">
				<img src="<?php echo STATIC_URL;?>images/colors.png" title="设置颜色" id="colors">
				<div class="yzm-content-error hidden"><i class="yzm-iconfont yzm-iconshanchu pointer" onclick="$('.yzm-content-error').addClass('hidden')"></i> 标题重复，但仍然可继续发布！</div>
			</div>

		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">属性：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<label>置顶[1] <input name="flag[]" type="checkbox" value="1" onclick="set_top()" id="settop"></label>&nbsp;&nbsp;
				<label>头条[2] <input name="flag[]" type="checkbox" value="2"/></label>&nbsp;&nbsp;
				<label>特荐[3] <input name="flag[]" type="checkbox" value="3"/></label>&nbsp;&nbsp;
				<label>推荐[4] <input name="flag[]" type="checkbox" value="4"/></label>&nbsp;&nbsp;
				<label>热点[5] <input name="flag[]" type="checkbox" value="5"/></label>&nbsp;&nbsp;
				<label>幻灯[6] <input name="flag[]" type="checkbox" value="6"/></label>&nbsp;&nbsp;
				<label>跳转[7] <input name="flag[]" type="checkbox" value="7" onclick="toggle(this)"/></label>&nbsp;&nbsp;
			</div>
		</div>
		<div class="row cl" style="display:none;" id="url">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>跳转URL：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" errortips="跳转URL不能为空！" name="url" placeholder="格式为“http://开头”">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>栏目：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
				<span class="select-box"><?php echo select_category('catid', $catid, '≡ 请选择栏目 ≡', 0, '', true, true, $modelid); ?></span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">TAG标签：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
			<div class="Hui-tags" style="width:88%;float:left;margin-right:5px;">
				<div class="Hui-tags-editor cl" style="padding: 5px 0 5px 24px;">
				<i class="Hui-tags-icon yzm-iconfont yzm-icontags" style="top:5px"></i>
					<div id="tag_default"></div>
					<div class="Hui-tags-iptwrap" style="width:50%">
						<input type="text" class="Hui-tags-input" maxlength="20" value="" id="tag_input" onblur="change_keyword()">
						<label class="Hui-tags-label">添加标签，用空格或回车分隔</label>
					</div>
				</div>
				<input type="hidden" class="Hui-tags-val" name="tag" value="" id="taglist">
			</div>
			 <a href="javascript:;" onclick="yzm_open('TAG标签选择','<?php echo U('tag/public_select');?>','650','400')" class="btn btn-primary radius">选择</a>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">关键词：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value=""  name="keywords" placeholder="每个关键字之间用“,”分隔">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">内容摘要：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="description" class="textarea"  placeholder="如不填写，则自动提取文章前250字符" datatype="*10-100" dragonfly="true" nullmsg="文章摘要不能为空！" onKeyUp="textarealength(this,250)"></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/250</p>
			</div>
		</div>		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">发布时间：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text laydate-icon" style="width:265px;height:30px;" name="inputtime" value="<?php echo date('Y-m-d H:i:s'); ?>" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">阅读权限：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box"  style="width:265px">
				<select id="select" name="groupids_view" class="select">
				<option value="0">开放浏览</option>
			    <?php 
				foreach($member_group as $val){
					echo '<option value="'.$val['groupid'].'">'.$val['name'].'</option>';
				}
			    ?>	
				</select>
				</span>  
				<span class="yzmcms_small">
					阅读收费：<input type="text" class="input-text" style="width:150px" value="0"  name="readpoint" onfocus="layer.tips('vip会员可免费查看', this, {tips:[1,'#666']});">
					<label class="mr-5"><input type="radio" name="paytype" value="1" checked>点</label> 
					<label><input type="radio" name="paytype" value="2">元</label>
				</span>  
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">缩 略 图：</label>
			<div class="formControls col-xs-8 col-sm-9" style="height:31px;">
				<div class="uploader-thum-container">
				<?php echo form::image('thumb', '', 'width:370px', true);?> <img src="<?php echo STATIC_URL;?>images/nopic.jpg" class="thumb" id="thumb_src">
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">来源：</label>
			<?php $copyfroms = get_copyfrom($modelid);?>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="<?php echo $copyfroms[0];?>" list="copyfroms"  name="copyfrom" style="width:150px">
				<datalist id="copyfroms">
					<?php 
						foreach($copyfroms as $v){
							echo '<option value="'.$v.'">';
						}
					?>
				</datalist>
				<span class="yzmcms_small">点击量：<input type="text" class="input-text" style="width:150px" value="<?php echo get_config('content_click_random') ? rand(50,150) : 0;?>"  name="click"></span>  
				<span class="yzmcms_small">作者昵称：<input type="text" class="input-text" style="width:150px" value="<?php echo $_SESSION['admininfo']['nickname'] ? $_SESSION['admininfo']['nickname'] : '管理员'; ?>"  name="nickname"></span>  
			</div>
		</div>
        <?php echo $string;?>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>内容：</label>
			<div class="formControls col-xs-8 col-sm-9"> 
			<?php echo form::editor('content', '', 'width:100%;height:400px', false);?>
			<div class="mt-5">
				<?php if(!get_config('auto_down_imag')){ ?>
				<span class="btn-mini btn-default mr-5" onclick="down_remote_img()">下载远程图片</span>
				<?php }?>
				<label title="提取内容第一张图片为缩略图"><input name="auto_thum" type="checkbox" value="1" <?php if(get_cookie('auto_thum')) echo 'checked';?> />提取内容第一张图片为缩略图</label>
			</div>
			</div>
		</div>
		<div class="footer_btn footer_border">
			<input type="hidden" name="status" value="1">
			<button name="dosubmit" class="btn btn-primary radius" type="submit" onclick="set_status(1)"><i class="yzm-iconfont yzm-iconfabusekuai"></i> 保存发布</button>
			<button name="dosubmit" class="btn btn-secondary radius" type="submit" onclick="set_status(0)"><i class="yzm-iconfont yzm-iconbaocun"></i> 保存草稿</button>
			<button name="continuity" class="btn btn-success radius" type="submit" onclick="set_status(1)"><i class="yzm-iconfont yzm-iconfabusekuai"></i> 保存后继续发布</button>
			<button onclick="yzm_content_close()" class="btn btn-default radius" type="button">&nbsp;&nbsp;关闭&nbsp;&nbsp;</button>
		</div>
		<input type="hidden"  value="10"  name="listorder">
	</form>
</article>

<?php include $this->admin_tpl('footer');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>js/jquery.colorpicker.js"></script>
<script type="text/javascript">
	function set_top(){
		if($('#settop').get(0).checked){
			$("input[name='listorder']").val('1');
		}else{
			$("input[name='listorder']").val('10');
		}	
	}
	
	function set_status(s){
		$("input[name='status']").val(s);	
	}
	
	function toggle(obj){ 
		$(obj).prop("checked") ? $("#url .input-text").addClass('required') : $("#url .input-text").removeClass('required');
        $("#url").toggle();
    }
	
	function yzm_content_close(){
		if(UE.getEditor('content').getContent()!=''){
			layer.confirm('内容未保存，确定要关闭吗？', {title:"操作提示"}, function(index){
				yzmcms_close();
			});
		}else{
			yzmcms_close();
		}
	}
	
	function checkall(){
		if($("input[name='title']").val()==''){
			layer.msg('标题不能为空！', {icon:2,time: 2000});
			return false;
		}
		if($("select[name='catid']").val()=='0'){
			layer.msg('请选择栏目！', {icon:2,time: 2000});
			return false;
		}
		var check = true;
		$(".required").each(function(){
			if($(this).val() == ''){
			  layer.msg($(this).attr('errortips'), {icon:2,time: 2000});
			  $(this).focus();
			  check = false;
			  return false;
			}
		})
		if(!check) return false;
		if(UE.getEditor('content').getContent()==''){
			layer.msg('内容不能为空！', {icon:2,time: 2000});
			return false;
		}
		return true;
	}

	function check_title() {
		var title = $("input[name='title']").val();
		if(title == ''){
			layer.msg('标题不能为空！', {icon:2,time: 2000});
			return false;
		}
		$.ajax({
            type: "GET",
            url: "<?php echo U('api/index/check_title');?>", 
            data: {title:title},
		    dataType: "json", 
            success: function (msg) {
				msg.status ? $(".yzm-content-error").addClass("hidden") : $(".yzm-content-error").removeClass("hidden");
            }
        })
        var keywords = $("[name=keywords]").val();
        if(keywords == ''){
			$.ajax({
	            type: "POST",
	            url: 'https://www.yzmcms.com/api/analysis', 
	            data: {content:title},
			    dataType: "json", 
	            success: function (msg) {
					if(msg.status && msg.data){
						$("[name=keywords]").val(msg.data);
					}
	            }
	        })
        }
	}
	
	function change_keyword() {
		var keywords = $("[name=keywords]").val();
		if(keywords == ''){
			var v = $("#taglist").val();
			if(v != '') v = v.substr(0,v.length-1);
			$("[name=keywords]").val(v);
		}
	}

	$("#colors").colorpicker({
	    fillcolor:true,
	    success:function(o,color){
	        $("input[name='title']").css("color",color);
	        $("#color").val(color);
	    },
		reset:function(o){
			$("input[name='title']").css("color","");
			$("#color").val('');
		}
	});

	function down_remote_img(){
		var ue = UE.getEditor('content');
		var content = ue.getContent();
		if(content == ''){
			layer.msg('内容不能为空！', {icon:2,time: 2000});
			return false;
		}

		layer.msg('正在下载远程图片……', { icon: 16, shade: 0.21, time:false });
		$.ajax({
            type: "POST",
            url: "<?php echo U('api/index/down_remote_img');?>", 
            data: {content: content},
		    dataType: "json", 
            success: function (msg) {
				if(msg.status){
					ue.setContent(msg.data);
					layer.msg('下载远程图片完成！', {icon:1,time:1000});
				}
            },
	        error: function (xhr) {
	            if(xhr.status != 200){
	                layer.alert('下载远程图片时出错，xhr状态码：'+xhr.status);
	                return false;
	            }
	        }
        })
	}
</script>

</body>
</html>